package com.swak.netty_udp.new_ver;

import java.util.Map;
import java.util.concurrent.TimeUnit;

import com.swak.OS;
import com.swak.exception.RemotingException;
import com.swak.reactivex.threads.Contexts;
import com.swak.reactivex.transport.Channel;
import com.swak.reactivex.transport.ChannelHandlerAdapter;
import com.swak.reactivex.transport.TransportMode;
import com.swak.reactivex.transport.resources.LoopResources;
import com.swak.reactivex.transport.udp.UdpNettyClient;
import com.swak.registry.URL;
import com.swak.utils.Fmt;
import com.swak.utils.Maps;

public class UdpClient {

	public static void main(String[] args) throws RemotingException {
		Map<String, String> parameters = Maps.newHashMap();
		URL url = new URL("Test", OS.ip(), 8888, parameters);
		LoopResources resources = Contexts.createEventLoopResources(TransportMode.OS, 1, 2, "Test.EventLoop-", false, 2,
				TimeUnit.SECONDS);
		
		@SuppressWarnings("unused")
		UdpNettyClient client = new UdpNettyClient(url, resources, new ChannelHandlerAdapter() {

			@Override
			public void connected(Channel channel) throws RemotingException {
				super.connected(channel);
				Fmt.out.println("connected");
			}

			@Override
			public void disconnected(Channel channel) throws RemotingException {
				super.disconnected(channel);
				Fmt.out.println("disconnected");
			}

			@Override
			public void sent(Channel channel, Object message) throws RemotingException {
				super.sent(channel, message);
				Fmt.out.println("sent");
			}

			@Override
			public void received(Channel channel, Object message) throws RemotingException {
				super.received(channel, message);
				Fmt.out.println("received");
			}

			@Override
			public void caught(Channel channel, Throwable exception) throws RemotingException {
				super.caught(channel, exception);
				Fmt.out.println("caught：" + exception);
			}
		});
	}
}
